1 % Generator: GNU source-highlight, by Lorenzo Bettini, http://www.gnu.org/software/src-highlite
3 {\ttfamily \raggedright {
5 \mbox{}\textit{\textcolor{Brown
}{/*
}} \\
6 \mbox{}\textit{\textcolor{Brown
}{\ \ Returns\ true\ if\ point\ a\ is\ inside\ convex\ polygon\ p.
}} \\
7 \mbox{}\textit{\textcolor{Brown
}{\ \ Note\ that\ if\ point\ a\ lies\ on\ the\ border\ of\ p\ it
}} \\
8 \mbox{}\textit{\textcolor{Brown
}{\ \ is\ considered\ outside.
}} \\
10 \mbox{}\textit{\textcolor{Brown
}{\ \ We\ assume\ p\ is\ convex!\ The\ result\ is\ useless\ if\ p
}} \\
11 \mbox{}\textit{\textcolor{Brown
}{\ \ is\ concave.
}} \\
12 \mbox{}\textit{\textcolor{Brown
}{\ */
}} \\
13 \mbox{}\textcolor{ForestGreen
}{bool
}\
\textbf{\textcolor{Black
}{insideConvexPolygon
}}\textcolor{BrickRed
}{(
}\textbf{\textcolor{Blue
}{const
}}\ vector
\textcolor{BrickRed
}{$<$
}point
\textcolor{BrickRed
}{$>$
}\
\textcolor{BrickRed
}{\&
}p
\textcolor{BrickRed
}{,
}\
\textbf{\textcolor{Blue
}{const
}}\ point\
\textcolor{BrickRed
}{\&
}a
\textcolor{BrickRed
}{)
}\textcolor{Red
}{\
{} \\
14 \mbox{}\ \
\textcolor{ForestGreen
}{int
}\ mask\
\textcolor{BrickRed
}{=
}\
\textcolor{Purple
}{0}\textcolor{BrickRed
}{;
} \\
15 \mbox{}\ \
\textbf{\textcolor{Blue
}{for
}}\
\textcolor{BrickRed
}{(
}\textcolor{ForestGreen
}{int
}\ i
\textcolor{BrickRed
}{=
}\textcolor{Purple
}{0}\textcolor{BrickRed
}{;
}\ i
\textcolor{BrickRed
}{$<$
}n
\textcolor{BrickRed
}{;
}\
\textcolor{BrickRed
}{++
}i
\textcolor{BrickRed
}{)
}\textcolor{Red
}{\
{} \\
16 \mbox{}\ \ \ \
\textcolor{ForestGreen
}{int
}\ j\
\textcolor{BrickRed
}{=
}\
\textcolor{BrickRed
}{(
}i
\textcolor{BrickRed
}{+
}\textcolor{Purple
}{1}\textcolor{BrickRed
}{)\%
}n
\textcolor{BrickRed
}{;
} \\
17 \mbox{}\ \ \ \
\textcolor{ForestGreen
}{double
}\ z\
\textcolor{BrickRed
}{=
}\
\textbf{\textcolor{Black
}{turn
}}\textcolor{BrickRed
}{(
}p
\textcolor{BrickRed
}{[}i
\textcolor{BrickRed
}{],
}\ p
\textcolor{BrickRed
}{[}j
\textcolor{BrickRed
}{],
}\ a
\textcolor{BrickRed
}{);
} \\
18 \mbox{}\ \ \ \
\textbf{\textcolor{Blue
}{if
}}\
\textcolor{BrickRed
}{(
}z\
\textcolor{BrickRed
}{$<$
}\
\textcolor{Purple
}{0.0}\textcolor{BrickRed
}{)
}\textcolor{Red
}{\
{} \\
19 \mbox{}\ \ \ \ \ \ mask\
\textcolor{BrickRed
}{$|$=
}\
\textcolor{Purple
}{1}\textcolor{BrickRed
}{;
} \\
20 \mbox{}\ \ \ \
\textcolor{Red
}{\
}}\textbf{\textcolor{Blue
}{else
}}\
\textbf{\textcolor{Blue
}{if
}}\
\textcolor{BrickRed
}{(
}z\
\textcolor{BrickRed
}{$>$
}\
\textcolor{Purple
}{0.0}\textcolor{BrickRed
}{)
}\textcolor{Red
}{\
{} \\
21 \mbox{}\ \ \ \ \ \ mask\
\textcolor{BrickRed
}{$|$=
}\
\textcolor{Purple
}{2}\textcolor{BrickRed
}{;
} \\
22 \mbox{}\ \ \ \
\textcolor{Red
}{\
}}\textbf{\textcolor{Blue
}{else
}}\
\textbf{\textcolor{Blue
}{if
}}\
\textcolor{BrickRed
}{(
}z\
\textcolor{BrickRed
}{==
}\
\textcolor{Purple
}{0.0}\textcolor{BrickRed
}{)
}\
\textbf{\textcolor{Blue
}{return
}}\
\textbf{\textcolor{Blue
}{false
}}\textcolor{BrickRed
}{;
} \\
23 \mbox{}\ \ \ \
\textbf{\textcolor{Blue
}{if
}}\
\textcolor{BrickRed
}{(
}mask\
\textcolor{BrickRed
}{==
}\
\textcolor{Purple
}{3}\textcolor{BrickRed
}{)
}\
\textbf{\textcolor{Blue
}{return
}}\
\textbf{\textcolor{Blue
}{false
}}\textcolor{BrickRed
}{;
} \\
24 \mbox{}\ \
\textcolor{Red
}{\
}} \\
25 \mbox{}\ \
\textbf{\textcolor{Blue
}{return
}}\ mask\
\textcolor{BrickRed
}{!=
}\
\textcolor{Purple
}{0}\textcolor{BrickRed
}{;
} \\
27 \mbox{}\textcolor{Red
}{\
}} \\
29 } \normalfont\normalsize